<?php 
$startdate=getParameter("startdate");
$enddate=getParameter("enddate");
$url=addParameter("filter", "ok","");

if ($startdate==null)
$startdate = date('d/m/Y', strtotime("first day of this month"));
if ($enddate==null)
$enddate = date('d/m/Y', strtotime("last day of this month"));
?>


<form action="<?=$url?>" method="Post">
Debut <input type="text" name="startdate" size="10" id="startdate" value="<?=@$startdate?>"/> Fin :<input type="text" name="enddate" size="10" id="enddate" value="<?=@$enddate?>"/>

<input type="image" value="submit" src="images/menu/filter.png" width="24" style="vertical-align: bottom;">
</form>

<script>
  $(function() {
    $( "#startdate" ).datepicker({ dateFormat: "dd/mm/yy" });
    $( "#enddate" ).datepicker({ dateFormat: "dd/mm/yy" });
  });

  </script>
  
  <br/>
  <?php 
  
  

  if ($startdate || $enddate)
  {

  
  	$startdate=formatDate($startdate,'d/m/Y','Y-m-d');

  	$enddate=formatDate($enddate,'d/m/Y','Y-m-d');
  	
?><div style="width: 50%;float:left;">
  <div style="padding-right: 5px;">
<?php 
  	
  	$bigtotal=0;
  	
  	$table="cabinet_depencemensuelle";
  	
  $SQL="SELECT
		cabinet_depencemensuelle.montant,
		cabinet_naturedepencemensuelle.libelle,
		cabinet_depencemensuelle.dateoperation
		FROM
		cabinet_depencemensuelle
		INNER JOIN cabinet_naturedepencemensuelle ON cabinet_naturedepencemensuelle.id = cabinet_depencemensuelle.depencetypeId
		WHERE
		cabinet_depencemensuelle.dateoperation BETWEEN '$startdate 00:00:00' AND '$enddate 23:59:59' 
		AND
		cabinet_depencemensuelle.paye = 'Paye' 
		And 
		cabinet_depencemensuelle.portalId=$portalId";

  $rs=ew_LoadRecordset($SQL);
  //echo $SQL;
  
  $total=0;
  ?>
    		<span class="phpmaker title" style="white-space: nowrap;"><img id="table_title_img" width="32" src="images/menu/<?=$table?>.png">
 		<span id="table_title"><?=getObjByKey("portal_objects","lib_".$LANG,"name",$table)?></span><br clear="all"></span><br/>
    		 		<table class="ewTable ewTableSeparate">
		  <tr class="ewTableRow">
    <th class="ewTableHeader">Libéllé</th>
  <th class="ewTableHeader">Montant</th>
    <th class="ewTableHeader">Date</th>
  </tr>
    		<?php 
  	while ($rs && !$rs->EOF)
  	{
  		$dateoperation=$rs->fields["dateoperation"];
  		$montant=$rs->fields["montant"];
  		$total+=$montant;
  		?>
  		<tr>
  		<td> <?=$rs->fields["libelle"]?> </td><td> <?=$montant?><?=$app_cabinet_currency?>   </td><td> <?=formatDatabaseDatetime($dateoperation)?></td>
  		</tr>
  		<?php 
  		$rs->MoveNext();
  	}
  	
  	
  ?></table>
  <h4>Total des dépences : <?=$total?><?=$app_cabinet_currency?></h4>
  <?php 
  $bigtotal+=$total;
  
  $table="cabinet_depence_fournisseur";
  
  $SQL="
  SELECT
cabinet_fournisseur_avance.fournisseurId,
cabinet_fournisseur_avance.date,
cabinet_fournisseur_avance.montant
FROM
cabinet_fournisseur_avance
WHERE
cabinet_fournisseur_avance.date BETWEEN '$startdate 00:00:00' AND '$enddate 23:59:59' AND cabinet_fournisseur_avance.portalId=$portalId";

  
  $rs=ew_LoadRecordset($SQL);
  //echo $SQL;
  $total=0;
  ?>
      		<span class="phpmaker title" style="white-space: nowrap;"><img id="table_title_img" width="32" src="images/menu/<?=$table?>.png">
 		<span id="table_title"><?=getObjByKey("portal_objects","lib_".$LANG,"name",$table)?></span><br clear="all"></span><br/>
    		 		<table class="ewTable ewTableSeparate">
		  <tr class="ewTableRow">
    <th class="ewTableHeader">Fournisseur</th>
  <th class="ewTableHeader">Montant</th>
    <th class="ewTableHeader">Date</th>
  </tr>

      		<?php 
    	while ($rs && !$rs->EOF)
    	{
    		$dateoperation=$rs->fields["date"];
    		$montant=$rs->fields["montant"];
			$fournisseurId=$rs->fields["fournisseurId"];
    		$total+=$montant;
			
			  $SQL2="SELECT
					cabinet_fournisseur.libelle as  nom
					FROM
					cabinet_fournisseur
					WHERE
					cabinet_fournisseur.id =$fournisseurId";

						  
			 $rs2=ew_LoadRecordset($SQL2);

    		?>
    		<tr>
  		<td> <?=$rs2->fields["nom"]?> </td><td> <?=$montant?><?=$app_cabinet_currency?>   </td><td> <?=formatDatabaseDatetime($dateoperation)?></td>
  		</tr>
    		<?php 
    		$rs->MoveNext();
    	}
    	

    	?>
    	</table>
    	  <h4>Total des dépences : <?=$total?><?=$app_cabinet_currency?></h4>
    	  <?php 
    	  $bigtotal+=$total;
    	
    	  $table="cabinet_depence_prothesiste";
    	$SQL="
    	SELECT
		cabinet_depence_prothesiste.prothesisteId,
    	cabinet_depence_prothesiste.avance as montant ,
    	cabinet_depence_prothesiste.libelle,
    	cabinet_depence_prothesiste.dateoperation
    	FROM
    	cabinet_depence_prothesiste
    	WHERE
    	cabinet_depence_prothesiste.dateoperation BETWEEN '$startdate 00:00:00' AND '$enddate 23:59:59' AND cabinet_depence_prothesiste.portalId=$portalId";
    	
    	$rs=ew_LoadRecordset($SQL);
    	//echo $SQL;
    	$total=0;
    	?>
    	      			<span class="phpmaker title" style="white-space: nowrap;"><img id="table_title_img" width="32" src="images/menu/<?=$table?>.png">
 		<span id="table_title"><?=getObjByKey("portal_objects","lib_".$LANG,"name",$table)?></span><br clear="all"></span><br/>
    			 		<table class="ewTable ewTableSeparate">
		  <tr class="ewTableRow">
	<th class="ewTableHeader">Prothesiste</th>
    <th class="ewTableHeader">Libéllé</th>
  <th class="ewTableHeader">Montant</th>
    <th class="ewTableHeader">Date</th>
  </tr>
    	      		<?php 
    	    	while ($rs && !$rs->EOF)
    	    	{
    	    		$montant=$rs->fields["montant"];
    	    		$total+=$montant;
    	    		$dateoperation=$rs->fields["dateoperation"];
					$prothesisteId=$rs->fields["prothesisteId"];
					
					
					  $SQL2="SELECT
						cabinet_prothesiste.libelle
						FROM
						cabinet_prothesiste
						WHERE
						cabinet_prothesiste.id = $prothesisteId";

						  
					$rs2=ew_LoadRecordset($SQL2);
    	    		
    	    		?>
    	    	<tr>
  		<td> <?=$rs2->fields["libelle"]?> </td><td> <?=$rs->fields["libelle"]?> </td><td> <?=$montant?><?=$app_cabinet_currency?>   </td><td> <?=formatDatabaseDatetime($dateoperation)?></td>
  		</tr>
    	    		<?php 
    	    		$rs->MoveNext();
    	    	}
    	    	

    	    	?></table>
    	    	  <h4>Total des dépences : <?=$total?><?=$app_cabinet_currency?></h4>
    	    	  <?php 
    	    	  $bigtotal+=$total;
    	    	  

    	    	  ?>
    	    	    <h3>Montant global des dépences de la période : <?=$bigtotal?><?=$app_cabinet_currency?></h3>
    	    	    <?php 
    	    	    
    	    	    ?>
    	    	    </div>
    	    	    </div>
    	    	    <div style="float:right;width: 50%;">
    	    	    <div style="padding-left: 5px;">
    	    	    <?php 
    	    	    //Recettes
    	    	    
    	    	    $table="cabinet_soins";
    	    	     
    	    	    $SQL="SELECT
cabinet_soins.recu as montant,
CONCAT(cabinet_dossier.numeroDeDossier,
cabinet_dossier.nom,
cabinet_dossier.prenom) as libelle,
cabinet_soins.date as dateoperation
FROM
cabinet_soins
INNER JOIN cabinet_dossier ON cabinet_soins.dossierId = cabinet_dossier.id
			WHERE
    	    	    cabinet_soins.date BETWEEN '$startdate 00:00:00' AND '$enddate 23:59:59' AND  cabinet_soins.portalId=$portalId";
    	    	    
    	    	    $rs=ew_LoadRecordset($SQL);
    	    	    //echo $SQL;
    	    	    
    	    	    $total=0;
    	    	    ?>
    	    	        		<span class="phpmaker title" style="white-space: nowrap;"><img id="table_title_img" width="32" src="images/menu/<?=$table?>.png">
    	    	     		<span id="table_title"><?=getObjByKey("portal_objects","lib_".$LANG,"name",$table)?></span><br clear="all"></span><br/>
    	    	        		 		<table class="ewTable ewTableSeparate">
    	    	    		  <tr class="ewTableRow">
    	    	        <th class="ewTableHeader">Libéllé</th>
    	    	      <th class="ewTableHeader">Montant</th>
    	    	        <th class="ewTableHeader">Date</th>
    	    	      </tr>
    	    	        		<?php 
    	    	      	while ($rs && !$rs->EOF)
    	    	      	{
    	    	      		$dateoperation=$rs->fields["dateoperation"];
    	    	      		$montant=$rs->fields["montant"];
    	    	      		$total+=$montant;
    	    	      		?>
    	    	      		<tr>
    	    	      		<td> <?=$rs->fields["libelle"]?> </td><td> <?=$montant?><?=$app_cabinet_currency?>   </td><td> <?=formatDatabaseDatetime($dateoperation)?></td>
    	    	      		</tr>
    	    	      		<?php 
    	    	      		$rs->MoveNext();
    	    	      	}
    	    	      	
    	    	      	
    	    	      ?></table>
    	    	      <h4>Total des Recettes : <?=$total?><?=$app_cabinet_currency?></h4>
    	    	      <?php 
    	    	    
    	    	    ?>
    	    	    </div>
    	    	    </div>
    	    	    <?php 
    	    	        	    	    
    	
  }
    
  
  ?>